package com.phicomm.appmanager;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;

import com.phicomm.mobilesecurity.R;
import com.phicomm.view.TitleBar;

public class AppManagerActivity extends FragmentActivity {

	private ViewPager mViewPager;
	private ArrayList<Fragment> mPagerList;
	private TitleBar mTitleBar;
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_app_manager);
		
		initView();
		initViewPager();
	
	}
	
	private void initView() {
		// TODO Auto-generated method stub
		mTitleBar = (TitleBar) findViewById(R.id.title_bar);
		mTitleBar.setTitleText(0, getString(R.string.app_manager));
		mTitleBar.setTitleText(1, getString(R.string.privileges_manager));
		mTitleBar.setTitleColor(0, getResources().getColor(R.color.red));
		mTitleBar.setBackClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				onBackPressed();
			}
		});

	}
	
	private void initViewPager() {
		// TODO Auto-generated method stub
		mViewPager = (ViewPager) findViewById(R.id.viewpager);
		mPagerList = new ArrayList<Fragment>();
		mPagerList.add(new appFragment());
		mPagerList.add(new PermissionFragment());
		
		FragmentManager fm = getSupportFragmentManager();
		mViewPager.setAdapter(new FragmentStatePagerAdapter(fm) {
			
			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return mPagerList.size();
			}
			
			@Override
			public Fragment getItem(int pos) {
				// TODO Auto-generated method stub
				return (mPagerList == null || mPagerList.size() == 0)?null:mPagerList.get(pos);
			}
		});
		mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
			
			@Override
			public void onPageSelected(int arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
				for (int i = 0; i < mPagerList.size(); i++) {
					if (i == arg0) {
						mTitleBar.setTitleColor(i, getResources().getColor(R.color.red));
					}else {
						mTitleBar.setTitleColor(i, getResources().getColor(R.color.black));
					}
				}
				
			}
			
			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}
	
	
}
